const headerTmpl = require("./tmpl/build/template");
require("./sass/header.scss");

import {getClubs} from "../../modules/dao.js";
import stateman from "../router/router.js";

class Header {
    constructor(dom, fetchedDoneCallback) {
        this.container = dom;
        this.data = null;
        this.callback = fetchedDoneCallback;
        this.init();
    }

    init () {
        getClubs().then((data)=>{
            this.data = data;
            this.render();
            if(typeof this.callback === "function"){
                this.callback(this.data);
            }
        }).catch((err)=>{
            console.error(err);
        });
    }

    render() {
        var html = headerTmpl("header", {list: this.data});
        $(this.container).html(html);
    }
}

export default Header;